<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #create_time="{ record }">
        {{ tool.dateFormat(record.create_time, 'yyyy-MM-dd hh:mm:ss', '-') }}
      </template>
      <template #operationAfterExtend="{ record }">
        <a-link @click="selectOperation('updateBalance',record)"><icon-double-right />补订单</a-link>
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import recordPaymentOrder from '@/api/record/recordPaymentOrder'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  recordPaymentOrder.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  recordPaymentOrder.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'record_payment_order',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 100,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: recordPaymentOrder.getList,
  recycleApi: recordPaymentOrder.getRecycleList
})

const columns = reactive([
  {
    title: "",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入"
    }
  },
  {
    title: "订单号",
    dataIndex: "order_sn",
    formType: "input",
    search: true,
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "第三方支付单号",
    dataIndex: "transaction_id",
    formType: "input",
    search: true,
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "用户ID",
    dataIndex: "user_id",
    formType: "input",
    search: true,
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入用户ID"
    }
  },
  {
    title: "优惠券ID",
    dataIndex: "coupon_id",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入优惠券ID"
    }
  },
  {
    title: "订单金额(分)",
    dataIndex: "money",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入订单金额(分)"
    }
  },
  {
    title: "折扣金额(分)",
    dataIndex: "discount",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入折扣金额(分)"
    }
  },
  {
    title: "实付金额(分)",
    dataIndex: "fact_money",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入实付金额(分)"
    }
  },
  {
    title: "到账金额",
    dataIndex: "received_amount",
    formType: "input"
  },
  {
    title: "支付方式",
    dataIndex: "method_id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入支付方式"
    }
  },
  {
    title: "ip",
    dataIndex: "ip",
    formType: "input",
    search: true
  },
  {
    title: "业务ID",
    dataIndex: "biz_id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入业务ID"
    }
  },
  {
    title: "业务类型1充值钻石",
    dataIndex: "biz_type",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入业务类型1充值钻石"
    }
  },
  {
    title: "订单完成时间",
    dataIndex: "complete_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "订单超时时间",
    dataIndex: "expire_time",
    formType: "input"
  },
  {
    title: "支付成功时间",
    dataIndex: "pay_time",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入支付成功时间"
    }
  },
  {
    title: "订单状态(0刚下单,1.已回调,2.支付成功,3.订单已关闭)",
    dataIndex: "status",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入订单状态(0刚下单,1.已回调,2.支付成功,3.订单已关闭)"
    }
  },
  {
    title: "所属代理",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入所属代理"
    }
  },
  {
    title: "创建时间",
    dataIndex: "create_time",
    width:180,
    formType: "range",
    search: true,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "update_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'record:paymentOrder' } </script>